import {takeEvery,put} from 'redux-saga/effects'
import {SAGA_ISLOGIN,ISLOGIN} from './actionType'
import axios from 'axios'
//login
function saga(){
    return takeEvery(SAGA_ISLOGIN,req)
}
function* req(res){
    // console.log(res.data)
    let {email,password}=res.data
    let a =yield axios({url:'/Legang/user/login',method:"POST"
    ,data:`email=${email}&password=${password}`,headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }})
    .then(res=>res)
    // console.log(a.data)
    if(!a.data.flag){
        window.localStorage.setItem('isLogin',false)     
        yield put(disp({isLogin:false,uid:null}));

    }
    else{
        window.localStorage.setItem('isLogin',true)
        window.localStorage.setItem('uid',a.data.data.uid)
        yield put(disp({isLogin:true,uid:a.data.data.uid}));
    }

}
function disp(data){
    // console.log(1111111)
    return {
        type:ISLOGIN,
        data
    }
}





export {saga}



